﻿using System;
using System.Web.UI;
using visinia.SmartEngine;
using visinia.SmartEngine.Modules;
using visinia.SmartEngine.Site;

namespace visinia.web
{
    public partial class DefaultPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int PageId = 0;
            Int32.TryParse(Request.QueryString["PageId"], out PageId);
            if (WebModuleController.LoadModules(PageId, Page, WebModuleController.MODES.USER))
            {   //disable viewstate
                EnableViewState = false;
                AddScriptVariables();
                WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "jquery/jquery-1.3.2.min.js");
                // for easy and light weight data transfer
                WebPageController.AddScriptLink(Page, WebRoots.GetJsRoot + "json/jquery.json-2.2.min.js");
                Header.Controls.Add(new LiteralControl("<link rel=\"shortcut icon\" type=\"image/x-icon\" href=\"favicon.ico\" />"));
                Page.DataBind();
            }
        }

        void Page_PreInit(Object sender, EventArgs e)
        {
            MasterPageFile = WebRoots.GetThemesRoot + SiteSettings.Theme + "/page.master";
        }

        private void AddScriptVariables()
        {
            string root = "<input type=\"hidden\" value=\"" + WebRoots.GetWebRoot + "\" id=\"WebRoots_GetWebRoot\" />";
            LiteralControl rootctrl = new LiteralControl(root);
            Page.Form.Controls.Add(rootctrl);
        }        
    }
}
